package com.weetop.aklyscan.presenter;

import android.app.Activity;

import com.blankj.utilcode.util.GsonUtils;
import com.weetop.aklyscan.base.mvp.BaseModel;
import com.weetop.aklyscan.base.mvp.BaseObserver;
import com.weetop.aklyscan.base.mvp.BasePresenter;
import com.weetop.aklyscan.bean.FittingDetailBean;
import com.weetop.aklyscan.bean.FittingInfo;
import com.weetop.aklyscan.bean.Into02Bean;
import com.weetop.aklyscan.bean.ProductDetailBean;
import com.weetop.aklyscan.bean.ScanShelfCodeBean;
import com.weetop.aklyscan.bean.TransferBoxBean;
import com.weetop.aklyscan.view.ZxInStockView;

import java.util.List;

import retrofit2.http.Field;

public class ZxInStockPresent extends BasePresenter<ZxInStockView> {

    public ZxInStockPresent(ZxInStockView baseView, Activity activity) {
        super(baseView, activity);
    }

    /**
     * @param type_id  产品类型：1产品；2配件
     * @param order_sn 入库单编号
     */
    public void inStockDetail01(String type_id, String order_sn) {
        addDisposable(apiServer.intoDetail01(type_id, order_sn), new BaseObserver<BaseModel<List<ProductDetailBean>>>(baseView) {
            @Override
            public void onSuccess(BaseModel<List<ProductDetailBean>> o) {
                baseView.getInStockDetail01Success(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }

    /**
     * @param type_id  产品类型：1产品；2配件
     * @param order_sn 入库单编号
     */
    public void inStockDetail02(String type_id, String order_sn) {
        addDisposable(apiServer.intoDetail02(type_id, order_sn), new BaseObserver<BaseModel<List<FittingDetailBean>>>(baseView) {
            @Override
            public void onSuccess(BaseModel<List<FittingDetailBean>> o) {
                baseView.getInStockDetail02Success(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }

    public void scanShelfCode(String code) {
        addDisposable(apiServer.scanShelfCode(code), new BaseObserver<BaseModel<ScanShelfCodeBean>>(baseView) {
            @Override
            public void onSuccess(BaseModel<ScanShelfCodeBean> o) {
                baseView.scanShelfCodeSuccess(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }

    public void searchList(String code) {
        addDisposable(apiServer.scanTransferBox(code), new BaseObserver<BaseModel<TransferBoxBean>>(baseView) {
            @Override
            public void onSuccess(BaseModel<TransferBoxBean> o) {
                baseView.getSearchResultSuccess(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }

    //items : List<IntoSaveBean>
    public void intoKuSave(String type_id, String order_sn, String tier_id, String items) {
//        String itemsString = GsonUtils.toJson(items);
        addDisposable(apiServer.intoKuSave(type_id, order_sn, tier_id, items), new BaseObserver<BaseModel<Object>>(baseView) {
            @Override
            public void onSuccess(BaseModel<Object> o) {
                baseView.saveIntoKuSuccess(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }


    public void scanFitting(String matter_code) {
        addDisposable(apiServer.Into07(matter_code), new BaseObserver<BaseModel<FittingInfo>>(baseView) {
            @Override
            public void onSuccess(BaseModel<FittingInfo> o) {
                baseView.getFittingInfoSuccess(matter_code,o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }
}
